<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/13
 * Time: 17:56
 */
include "config.php";
include "status.php";
if($_SERVER["REQUEST_METHOD"]!="POST")
{
    print_r(json_encode(Status::$reg_nget));
    return;
}
$UID = $_POST["u_id"]; // 用户id
$GID = $_POST["gid"];//产品id
$CNUM = $_POST["num"];
$sqlQuery = "SELECT * FROM cart WHERE u_id= ? ;";
$stmt = $conn->prepare($sqlQuery);
$stmt->bind_param("i", $UID);
$stmt->execute();
$queryResult = $stmt->get_result();
$sqlUpdate = "UPDATE cart SET  c_num=? ,c_total=c_num*c_nprice WHERE u_id=?  and g_id=?";

$stmtU = $conn->prepare($sqlUpdate);
$stmtU->bind_param("iii", $CNUM,$UID,$GID);
$stmtU->execute();

if($stmtU->affected_rows >= 1){
    print_r(json_encode(array("msg" => "成功减掉一件商品u", "status" => 1)));
} else {
    print_r(json_encode(array("msg" => "失败u", "status" => -1)));
}
$stmtU->close();
$conn->close();